package com.wjm.myalipayplugin;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.wjm.pluginstand.PayInterfaceBroadcast;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ProxyBroadCast extends BroadcastReceiver{
    private PayInterfaceBroadcast payInterfaceBroadcast;
    private String className;

    public ProxyBroadCast(String className, Context context) {
        this.className=className;
        try {
            Class<?> aClass = PluginManager.getInstance().getDexClassLoader().loadClass(className);
            Constructor<?> constructor = aClass.getConstructor(new Class[]{});
            Object instance = constructor.newInstance(new Object[]{});
            payInterfaceBroadcast=(PayInterfaceBroadcast)instance;
            payInterfaceBroadcast.attach(context);
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (NoSuchMethodException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        payInterfaceBroadcast.onReceive(context,intent);
    }
}
